package com.bw.module_detail.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_detail.databinding.ItemVideoDetailBinding
import com.bw.module_detail.model.entity.VideoEntity

/**
 * @author ykj
 * @date 2025-10-22 10:23
 * @description
 */
class DetailVideoAdapter:RecyclerView.Adapter<DetailVideoAdapter.VideoViewHolder>() {

    private var videoList = mutableListOf<VideoEntity>()

    class VideoViewHolder(
        val binding:ItemVideoDetailBinding
    ):RecyclerView.ViewHolder(binding.root)

    fun setData(mList: List<VideoEntity>){
        videoList.clear()
        videoList.addAll(mList)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): VideoViewHolder {
        val binding = ItemVideoDetailBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return VideoViewHolder(binding)
    }

    override fun onBindViewHolder(holder: VideoViewHolder, position: Int) {
        val item = videoList[position]
        holder.binding.detail = item
    }

    override fun getItemCount(): Int {
        return videoList.size
    }

}
